package com.wisdom.benefit.jufa.product;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wisdom.benefit.jufa.R;
import com.wisdom.benefit.jufa.base.BaseActivity;
import com.wisdom.benefit.jufa.base.BaseApplication;
import com.wisdom.benefit.jufa.net.RetrofitService;
import com.wisdom.benefit.jufa.utils.CommonUtils;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import cn.ycbjie.ycstatusbarlib.bar.YCAppBar;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * 当前收款账户
 */
public class CollectionAccountActivity extends BaseActivity {
    private RelativeLayout backRl;
    private TextView nameTv, accountTv, phoneTv;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        userInfo(BaseApplication.getContext().getUserId());
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_collection_account;
    }

    @Override
    protected void initViews() {
        //返回按钮
        backRl = findViewById(R.id.collect_account_back);
        //设置状态栏为蓝色
        YCAppBar.setStatusBarColor(CollectionAccountActivity.this,
                ContextCompat.getColor(CollectionAccountActivity.this,
                        R.color.blue));
        setClick();
        //姓名
        nameTv = findViewById(R.id.user_info_name);
        //账号
        accountTv = findViewById(R.id.user_info_account);
        //手机号
        phoneTv = findViewById(R.id.user_info_phone);
    }

    /**
     * 设置监听
     *
     * @return
     */
    private void setClick() {
        //返回按钮
        backRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 个人信息
     */
    private void userInfo(String userId) {
        showProgressDialog("");
        addDisposable(RetrofitService.getNetService()
                .personalInformation(userId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(response -> {
                    hideProgressDialog();
                    if (response.getCode() == 0) {
                        //姓名
                        nameTv.setText(response.getData().getName());
                        accountTv.setText(response.getData().getUserName());
                        phoneTv.setText(response.getData().getMobile());
                    } else {
                        showBindToast(response.getMsg());
                    }
                }, throwable -> {
                    throwable.printStackTrace();
                    hideProgressDialog();
                    if (CommonUtils.isNetworkAvailable(getContext()))
                        showBindToast("获取数据失败");
                    else
                        showBindToast("无网络连接，请稍后再试");
                }));
    }


    @Override
    protected int getTitleStringRes() {
        return 0;
    }
}
